<?php
	// top section of page inclues all of the search types, regardless of search results
	
	echo '<div id="search-main">
			<table>
				<tr>
					<td>
						<h2>Search for Textbooks by Subject Code</h2>
						<p>Enter the subject codes below that you would like to search for.</p>
						';
	include("bookshop_php/search_subject.php");
	echo '			</td>
					<td>
						<h2>Search for Textbooks by Keyword</h2>
						<p>Enter the keyword(s) below that you would like to search for.</p>
						<div id="search-keyword">
						';
	include("bookshop_php/search_keyword.php");
	echo '				</div>
					</td>
				</tr>
			</table>
		</div>
		';
	
	if (isset($_GET['searchsubject'])) {
		$searchstring = "";
		$subjects = $_POST['subject'];
		
		for ($i = 0; $i < 4; $i++) {
			if ($subjects[$i] != "") {
				if ($searchstring == "") {
					$searchstring = $subjects[$i];
				}
				else {
					$searchstring = $searchstring . ' ' . $subjects[$i];
				}
			}
		}
		
		if ($searchstring != "") {
			echo '<div id="search-result">
					<h3>Search Results for Subject Codes: ' . $searchstring . ':</h3>
				</div>
				';
			// search results bit goes here
			
		}
	}
	else if (isset($_GET['searchkeyword'])) {
		if (isset($_GET['codecomplete'])) {
			$genericbook = '<div id="bookshop-mybooks-generic">
							<table>
								<tr>
									<td>Author:</td>
									<td>SURNAME</td>
								</tr>
								<tr>
									<td>Publisher:</td>
									<td>EXAMPLE</td>
								</tr>
								<tr>
									<td>Edition:</td>
									<td>3</td>
								</tr>
								<tr>
									<td>ISBN/APN:</td>
									<td>0735619670/9780735619678</td>
								</tr>
								<tr>
									<td>RRP:</td>
									<td>$99.95</td>
								</tr>
								<tr>
									<td>JCU Price:</td>
									<td>$87.96</td>
								</tr>
								<tr>
									<td>Stock:</td>
									<td>Currently in stock</td>
								</tr>
								<tr>
									<td>Order Status:</td>
									<td>Not on order</td>
								</tr>
							</table>
							</div>
							';
							
			if (isset($_GET['expand'])) {
				$result = '<li class="minus"><a href="?searchkeyword&codecomplete">Code Complete</a></li>' . $genericbook;
			}
			else {
				$result = '<li><a href="?searchkeyword&codecomplete&expand">Code Complete</a></li>';
			}
			echo '<div id="search-result">
					<h3>Search Results for "Code Complete":</h3>
					<ul id="containerul" class="plus">
						' . $result . '
					</ul>
				</div>
				';	
		}
		else {
			if (isset($_POST['keywords'])) {
				if ($_POST['keywords'] == "code complete") {
					$result = '<li><a href="?searchkeyword&codecomplete&expand">Code Complete</a></li>';
				}
				else {
					$result = "";
				}
				
				if ($_POST['keywords'] != "") {
					echo '<div id="search-result">
							<h3>Search Results for "' . $_POST['keywords'] . '":</h3>
							';
					
					if ($result != "") {
							echo '<ul id="containerul" class="plus">
									' . $result . '
									</ul>
									';
								
					}
					else {
						echo '<p>No search results were returned.</p>
								';	
					}
					
					echo '</div>
						';
				}
			}
		}
	}
?>